package com.asj.vivo.lock.useless;

/**
 * 草稿，存放暂时注释的内容
 * */
public class ScratchPaper {

        /*Button button = this.findViewById(R.id.lock_button);
        button.setOnClickListener(v -> {
            //TODO:解除锁定页面，未完成，暂时不允许解除锁定
//            new OPPOSDKService().clearScreenPinningApp("com.asj");

            TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            PhoneStateListener phoneStateListener = new PhoneStateListener() {
                public void onCallStateChanged(int state, String incomingNumber) {
                    switch (state) {
                        case TelephonyManager.CALL_STATE_RINGING:
                            // 电话响铃
                            break;
                        case TelephonyManager.CALL_STATE_OFFHOOK:
                            // 电话通话中
                            break;
                        case TelephonyManager.CALL_STATE_IDLE:
                            // 电话处于空闲状态
                            break;
                    }
                }
            };
            // 注册监听器
            telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);

            Intent callIntent = new Intent(Intent.ACTION_CALL);
            callIntent.setData(Uri.parse("tel:" + phone));
            callIntent.putExtra("returnPage","false03");
            this.startActivity(callIntent);
        });*/

    /*//判断中台转发MDM的信息是否为要操作SDK
                if(contentData.get(KEY_IS_SDK_INSTRUCT.getValue()) != null){
                    //调用操作中心方法，并将参数通过构造方法设置
                    try {
                        new OPPOSDKService(contentData,mainActivity).operatingCenter();
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
                //监听锁机操作
                else if(contentData.get("lockMachine") != null){
                    //进行锁机
                    if(Objects.equals(contentData.get("lockMachine").getAsString(), "true")){
                        mainActivity.finishAffinity();
                        String remarks = contentData.get("remarks").getAsString();
                        String phone = contentData.get("phone").getAsString();

                        Intent intent = new Intent(mainActivity, MainActivity.class);
                        //跳转到锁机页面
                        intent.putExtra("isLock","true");
                        intent.putExtra("returnPage","false");
                        intent.putExtra("phone",phone);
                        intent.putExtra("remarks",remarks);
                        // 如果需要传递数据，可以使用intent.putExtra()方法
                        try {
                            mainActivity.startActivity(intent);
                        }catch (Exception e){
                            System.out.println("跳转页面异常！"+e);
                        }
                        contentData.addProperty("resultMsg",new OPPOControlService(mainActivity).lockMachine());
                    }
                    //取消锁机
                    else{
                        mainActivity.finishAffinity();
                        Intent intent = new Intent(mainActivity, MainActivity.class);
                        //跳转到锁机页面
                        intent.putExtra("content","已解锁，请上滑动离开页面");
                        intent.putExtra("isLock","false");
                        intent.putExtra("returnPage","false02");
                        // 如果需要传递数据，可以使用intent.putExtra()方法
                        try {
                            mainActivity.startActivity(intent);
                        }catch (Exception e){
                            System.out.println("跳转页面异常！"+e);
                        }
                        contentData.addProperty("resultMsg",new OPPOControlService(mainActivity).unlockMachine());
                    }
                    try {
                        RequestMDMService.sendResult(contentData.toString(),"/operationalOrder/lockReceiveResultUrl");
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
                //取消监管操作
                else if(contentData.get("supervision") != null){
                    if(!Objects.equals(contentData.get("supervision").getAsString(), "true")){
                        return;
                    }
                    //取消监管
                    contentData.addProperty("resultMsg",new OPPOControlService(mainActivity).cancelSupervisionUrl());
                    String result = new OPPOControlService(mainActivity).cancelSupervisionUrl();
                    if(result.equals("result_success")){
                        //取消监管的设置成功，弹框提示，并退出程序，将该程序在该设备上删除
                        //关闭webSocket客户端
                        webSocket.close(1000,"取消监管成功！删除程序上的设备并关闭客户端的连接");
                        //提示页面即将关闭
                        mainActivity.runOnUiThread(() -> {
                            Toast toast = Toast.makeText(mainActivity, "已成功取消监管，两秒后自动将该软件从设备上移除", Toast.LENGTH_SHORT);
                            toast.show();
                            //延迟关闭页面
                            new Handler(Looper.getMainLooper()).postDelayed(mainActivity::finish, 2400);
                            //删除该程序在设备上
                            new Handler(Looper.getMainLooper()).postDelayed(new OPPOControlService(mainActivity)::seeYouLater, 2400);
                        });
                        //清空所有黑名单
                        new OPPOControlService(mainActivity).clearBlackList();
                    }
                    try {
                        RequestMDMService.sendResult(contentData.toString(),"/operationalOrder/cancelSupervisionSupervision");
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
                //监听设置黑名单列表
                else if(contentData.get("setBlackList") != null){
                    new ControlDeviceService(mainActivity).setBlackList(contentData);
                    //返回给mdm设置结果
                    try {
                        RequestMDMService.sendResult(contentData.toString(),"/operationalOrder/receiveSettingBlackListInfoResultUrl");
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
                //同步设备信息
                else if(contentData.get("updateDevice") != null){
                    try {
                        new OPPOSDKService(contentData,mainActivity).getNewDeviceInfo();
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }*/


    /*mainActivity.runOnUiThread(() -> {
                    // 这里根据bind的值来更新UI
                    if (isExist != null && "200".equals(isExist.get("code").getAsString())) {
                        Toast.makeText(mainActivity, "设备已绑定，已激活锁", Toast.LENGTH_LONG).show();
                        // 进行其他UI操作，如隐藏加载指示器、更新界面元素等
                    } else {
                        Toast.makeText(mainActivity, "设备未绑定", Toast.LENGTH_LONG).show();
                    }
                });*/



    //初始化进度组件
        /*ProgressBarService.setProgressBar(this);
        ProgressBarService.setRecyclerView(this);
        ProgressBarService.initProgressBarValue(9,0,this);*/

    //未绑定设备，解除其他已成功的监管项
//        new OPPOControlService(this).cancelSupervisionUrl();
    /*
     * 初始化中台的webSocket客户端，进行连接
     * 目的：中台负责管理第三方厂商，需要时刻与APP保持通讯，记录APP的状态是否正常，以及第三方厂商的SDK是否正常）
     * */
//        WebSocketClient.getInstance(this).initWebSocket();

    //不加载输入框页面了
    //setContentView(R.layout.activity_main);



    //每次打开页面默认设置固定屏幕，判断设备已被监管则取消固定
//                new OPPOControlService(this).lockMachine();



            /*//提示页面
            Intent intent = new Intent(mainActivity, MainActivity.class);
            //跳转到成功绑定页面
            intent.putExtra("content","已成功绑定，请上滑离开页面");
            intent.putExtra("isLock","false");
            intent.putExtra("returnPage","false02");
            mainActivity.startActivity(intent);*/


    /**
     * 查询各项添加的是否正常
     */
    /*public void lockCheck(){
        OPPOSDKService opposdkService = new OPPOSDKService(context);
        String packName = "com.asj";
        //检查常驻后台应用
        List<String> persistentApp = opposdkService.getPersistentApp();
        if(!persistentApp.contains(packName)){
            //常驻后台
            opposdkService.addPersistentApp(packName);
        }
        //检查防卸载
        List<String> disallowUninstallPackageList = opposdkService.getDisallowUninstallPackageList();
        if(!disallowUninstallPackageList.contains(packName)){
            opposdkService.addDisallowedUninstallPackages(packName);
        }
        //检查恢复出厂
        boolean restoreFactoryDisabled = opposdkService.isRestoreFactoryDisabled();
        if(!restoreFactoryDisabled){
            opposdkService.setRestoreFactoryDisabled("true");
        }
        //检查禁止关闭定位服务
        int gpsPolicies = opposdkService.getGpsPolicies();
        if(gpsPolicies != 1){
            opposdkService.setGpsPolicies("1");
        }
        //检查设置开机自启动
        boolean allowedRunningApp = opposdkService.getAllowedRunningApp(packName);
        if(!allowedRunningApp){
            opposdkService.addAllowedRunningApp(packName);
        }
    }*/



    /**
     * 输入用户编码（此时是确定用户需要绑定设备的）
     * */
    /*public static void inputDeviceCode(MainActivity mainActivity){
        // 设置按钮点击事件
        Button button = mainActivity.findViewById(R.id.button);
        EditText editText = mainActivity.findViewById(R.id.editText);
        OPPOSDKService instance = new OPPOSDKService(mainActivity);
        button.setOnClickListener(v -> new Thread(() -> {
            // 获取门店编码
            String storeCode = editText.getText().toString().trim();

        }).start());
    }*/





    /*public static void inputDeviceCode(MainActivity mainActivity){
        // 设置按钮点击事件
        Button button = mainActivity.findViewById(R.id.button);
        button.setOnClickListener(v -> new Thread(() -> {
            //设置管理员权限
            OPPOSDKService opposdkService = new OPPOSDKService(mainActivity);
            *//*ControlDeviceService deviceService = new ControlDeviceService();
            deviceService.startActivityForResult(mainActivity);*//*
            String s = opposdkService.setEmmAdmin(true);

            String deviceOwner = opposdkService.setDeviceOwner();
            mainActivity.runOnUiThread(() -> {
                // 这里根据bind的值来更新UI
                Toast.makeText(mainActivity, "管理员权限设置::"+s, Toast.LENGTH_LONG).show();
                // 这里根据bind的值来更新UI
                if ("result_success".equals(deviceOwner)) {
                    Toast.makeText(mainActivity, "deviceOwner设置成功", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(mainActivity, "deviceOwner设置失败", Toast.LENGTH_LONG).show();
                }
            });
        }).start());
    }*/

    /*public static void inputDeviceCode05(MainActivity mainActivity){
        // 设置按钮点击事件
        Button button = mainActivity.findViewById(R.id.button05);
        button.setOnClickListener(v -> new Thread(() -> {
            //取消DO身份
            OPPOSDKService opposdkService = new OPPOSDKService(mainActivity);
            String s = opposdkService.clearDeviceOwner();
            ControlDeviceService controlDeviceService = new ControlDeviceService();
            String s2 = opposdkService.setEmmAdmin(false);
            controlDeviceService.removeActiveAdmin(mainActivity);
            mainActivity.runOnUiThread(() -> {
                // 这里根据bind的值来更新UI
                Toast.makeText(mainActivity, "管理员权限取消"+s2+"/DO:"+s, Toast.LENGTH_LONG).show();
            });
        }).start());
    }*/

    /*public static void inputDeviceCode2(MainActivity mainActivity){
        Button button = mainActivity.findViewById(R.id.button02);
        button.setOnClickListener(v -> new Thread(() -> {
            OPPOSDKService opposdkService = new OPPOSDKService(mainActivity);
            String deviceOwner = opposdkService.setDeviceOwner(mainActivity);
            mainActivity.runOnUiThread(() -> {
                // 这里根据bind的值来更新UI
                if ("result_success".equals(deviceOwner)) {
                    Toast.makeText(mainActivity, "deviceOwner设置成功", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(mainActivity, "deviceOwner设置失败", Toast.LENGTH_LONG).show();
                }
            });
        }).start());
    }*/

    /*public static void inputDeviceCode3(MainActivity mainActivity){
        // 设置按钮点击事件
        Button button = mainActivity.findViewById(R.id.button03);
        EditText editText = mainActivity.findViewById(R.id.editText);
        button.setOnClickListener(v -> new Thread(() -> {
            OPPOSDKService opposdkService = new OPPOSDKService(mainActivity);

            boolean setPassword = opposdkService.setPassword("true", editText.getText().toString());
            mainActivity.runOnUiThread(() -> {
                // 这里根据bind的值来更新UI
                if (setPassword) {
                    //熄屏
                    opposdkService.DeviceLocked("false");
                    Toast.makeText(mainActivity, "锁屏密码设置成功", Toast.LENGTH_LONG).show();
                    // 进行其他UI操作，如隐藏加载指示器、更新界面元素等
                } else {
                    Toast.makeText(mainActivity, "锁屏密码设置失败", Toast.LENGTH_LONG).show();
                }
            });
        }).start());
    }

    public static void inputDeviceCode4(MainActivity mainActivity){
        // 设置按钮点击事件
        Button button = mainActivity.findViewById(R.id.button04);
        // 获取当前应用的包名
        button.setOnClickListener(v -> new Thread(() -> {
            OPPOSDKService opposdkService = new OPPOSDKService(mainActivity);
            boolean clearPassword = opposdkService.setPassword("false", "");
            mainActivity.runOnUiThread(() -> {
                if(clearPassword){
                    //设置锁屏密码
                    Toast.makeText(mainActivity, "清除密码设置成功", Toast.LENGTH_LONG).show();
                }else{
                    Toast.makeText(mainActivity, "清除密码失败", Toast.LENGTH_LONG).show();
                }
            });

        }).start());
    }*/


}
